import 'package:WebTest/animation/heroAnimationContentPage.dart';
import 'package:WebTest/animation/heroImageDetail.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: HeroHomePage(),
    );
  }
}

class HeroHomePage extends StatelessWidget {
  const HeroHomePage({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Material App Bar'),
      ),
      body: Center(
        child: GridView(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2,
              crossAxisSpacing: 8,
              mainAxisSpacing: 8,
              childAspectRatio: 16 / 9),
          children: List.generate(20, (index) {
            final String imageUrl = "https://picsum.photos/480/270?random=$index";
            return GestureDetector(
              child: Hero(
                tag: imageUrl,
                child: Image.network(
                  imageUrl,
                  fit: BoxFit.cover,
                ),
              ),
              onTap: () {
                Navigator.of(context).push(PageRouteBuilder(
                  transitionDuration: Duration(milliseconds: 1500),
                  pageBuilder: (context,animation1,animation2){
                    return FadeTransition(
                      child: HeroImageDetailPage(imageUrl),
                      opacity: animation1,
                    );
                  }
                ));
              },
            );
          }),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.poll),
        onPressed: () {
//          presentController
//          Navigator.of(context).push(MaterialPageRoute(
//            builder: (ctx){
//              return HeroContentPage();
//            },
//            fullscreenDialog: true,
//          ));
          Navigator.of(context).push(PageRouteBuilder(
              transitionDuration: Duration(seconds: 1),
              pageBuilder: (context, animation1, animation2) {
                return FadeTransition(
                  child: HeroContentPage(),
                  opacity: animation1,
                );
              }));
        },
      ),
    );
  }
}
